﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Text;

namespace subtitle_modifier
{
    public class Record
    {
        private bool formated;

        public bool Formated
        {
            get { return formated; }
            set { formated = value; }
        }
        private List<string> m_Sentences;
        private int m_Id;

        public int Id
        {
            get { return m_Id; }
            set { m_Id = value; }
        }
        private TimeSpan m_StartShowingTime;

        public TimeSpan StartShowingTime
        {
            get { return m_StartShowingTime; }
            set { m_StartShowingTime = value; }
        }
        private TimeSpan m_EndShowingTime;

        public TimeSpan EndShowingTime
        {
            get { return m_EndShowingTime; }
            set { m_EndShowingTime = value; }
        }
        
        public Record(  )
        {
            m_Sentences = new List<string>();
        }
        public void AddSentence(string Sentence)
        {
            m_Sentences.Add(Sentence);
            if (Sentence.Contains('<') || Sentence.Contains('>'))
            {
                formated = true;
            }
        }
        public int GetSentencesCount()
        {
            return m_Sentences.Count;
        }
        public void SetSentenceAt(int Index, string Sentence)
        {
            m_Sentences[Index] = Sentence;
        }
        public string GetSentenceAt(int Index)
        {
            return (string)m_Sentences[Index];
        }
        public override  string ToString()
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("{0}\r\n{1:00}:{2:00}:{3:00},{4:000} --> {5:00}:{6:00}:{7:00},{8:000}\r\n", 
                                m_Id, 
                                m_StartShowingTime.Hours ,m_StartShowingTime.Minutes ,m_StartShowingTime.Seconds ,m_StartShowingTime.Milliseconds ,
                                m_EndShowingTime.Hours, m_EndShowingTime.Minutes, m_EndShowingTime.Seconds, m_EndShowingTime.Milliseconds);
            foreach (string Sentence in m_Sentences)
            {
                builder.Append(Sentence+"\r\n");
            }
            builder.Append("\r\n");
            return builder.ToString();
        }

        public void AddTme(TimeSpan TimeToAdd)
        {
            m_StartShowingTime += TimeToAdd;
            m_EndShowingTime += TimeToAdd;
        }
        public int ContainsTime(TimeSpan Time)
        {
            if (m_StartShowingTime <= Time && Time <= m_EndShowingTime)
            {
                return 0;
            }
            else if (m_StartShowingTime > Time)
            {
                return -1;
            }
            else
            {
                return 1;
            }
        }

        public string AppendSentences()
        {
            string AllSentences = "";
            foreach (string sen in m_Sentences)
            {
                AllSentences += " " + sen;
            }
            return AllSentences;
        }
    }
}